@import '~@hi-ui/core-css/lib/index.scss';

$prefix: '#{$component-prefix}-progress' !default;
$progress-color-map: (
  'warning': use-color-mode('warning'),
  'success': use-color-mode('success'),
  'error': use-color-mode('danger'),
  'primary': use-color-mode('primary')
) !default;

.#{$prefix} {
  display: inline-flex;
  align-items: center;
  width: 100%;

  &--sm {
    .#{$prefix}__inner {
      height: 2px;
    }
  }

  &--md {
    .#{$prefix}__inner {
      height: 4px;
    }
  }

  &--lg {
    .#{$prefix}__inner {
      height: 8px;
    }
  }

  &__inner {
    position: relative;
    flex: 1;
    border-radius: use-border-radius('full');
    overflow: hidden;
    background-color: use-color('gray', 200);

    &--active {
      .#{$prefix}__value {
        &::before {
          position: absolute;
          top: 0;
          right: 0;
          bottom: 0;
          left: 0;
          background: use-color-static('white');
          opacity: 0;
          content: '';
          animation: hi-progress-active 2.4s cubic-bezier(0.23, 1, 0.32, 1) infinite;
        }
      }

      @keyframes hi-progress-active {
        0% {
          width: 0;
          opacity: 0.1;
        }

        20% {
          width: 0;
          opacity: 0.5;
        }

        100% {
          width: 100%;
          opacity: 0;
        }
      }
    }

    .#{$prefix}__content {
      &--right {
        right: 0;
        transform: translateX(calc(100% + #{use-spacing(4)}));
        color: use-color('gray', 700);
      }

      color: use-color-static('white');
      position: absolute;
      right: use-spacing(4);
      height: 100%;
      display: flex;
      align-items: center;
      margin: 0;
    }
  }

  &__content {
    font-size: use-text-size('normal');
    margin-left: use-spacing(10);
    color: use-color('gray', 700);
    white-space: nowrap;
  }

  &__buffer,
  &__value {
    // cover to parent element content
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transition: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: use-border-radius('full');
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  &__buffer {
    color: inherit;
    background: linear-gradient(90deg, hsla(0, 0%, 100%, 0.7), hsla(0, 0%, 100%, 0.7)), currentColor;
  }

  &__value {
    color: inherit;

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        background-color: $value;
      }
    }

    background-color: currentColor;

    .#{$prefix}--indeterminate & {
      transform-origin: 50% 50%;
      animation: linear-bar-indeterminate 1s linear infinite;
    }
  }

  @keyframes linear-bar-indeterminate {
    0% {
      transform: translate(-50%) scaleX(0);
    }

    50% {
      transform: translate(0) scaleX(0.35);
    }

    100% {
      transform: translate(50%) scaleX(0.05);
    }
  }
}

$circle-progress-prefix: '#{$component-prefix}-circle-progress' !default;

.#{$circle-progress-prefix} {
  position: relative;
  display: inline-block;
  font-size: use-text-size('sm');

  &--lg {
    font-size: use-text-size('normal');
  }

  &__text {
    display: block;
    position: absolute;
    width: 100%;
    text-align: center;
    line-height: 1;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        svg[class^=hi-v4-icon] {
          color: $value;
        }
      }
    }
  }

  &__background {
    fill: none;
    stroke: use-color('gray', 200);
  }

  &__circle {
    fill: none;
    stroke: use-color-mode('primary');
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.4s cubic-bezier(0.3, 0, 0.7, 1);

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        stroke: $value;
      }
    }
  }
}

$dashboard-progress-prefix: '#{$component-prefix}-dashboard-progress' !default;

.#{$dashboard-progress-prefix} {
  position: relative;
  display: inline-block;

  &__text {
    display: block;
    position: absolute;
    width: 100%;
    text-align: center;
    line-height: 1;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        svg[class^=hi-v4-icon] {
          color: $value;
        }
      }
    }
  }

  &__background {
    fill: none;
    stroke: use-color('gray', 200);
  }

  &__circle {
    fill: none;
    stroke: use-color-mode('primary');
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.4s cubic-bezier(0.3, 0, 0.7, 1);

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        stroke: $value;
      }
    }
  }

  &__dashboard {
    fill: none;
    stroke: use-color-mode('primary');
    transition: stroke-dasharray 0.4s cubic-bezier(0.3, 0, 0.7, 1);

    @each $key, $value in $progress-color-map {
      &--#{$key} {
        stroke: $value;
      }
    }
  }
}
